package cn.progen.model;


import cn.progen.util.StringUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


public class Table implements Serializable {
	private String name;
	private String className;

	
	private List<String> importPacks=new ArrayList<String>();
	
	private List<Fileds> fileds;

	private List<Table> relationTables=new ArrayList<>();

	private Integer isList=1;

	public Integer getIsList() {
		return isList;
	}

	public void setIsList(Integer isList) {
		this.isList = isList;
	}

	public List<Table> getRelationTables() {
		return relationTables;
	}



	public void setRelationTables(List<Table> relationTables) {
		this.relationTables = relationTables;
	}

	private List<Relation> relations=new ArrayList<>();

	public List<Relation> getRelations() {
		return relations;
	}

	public void setRelations(List<Relation> relations) {
		this.relations = relations;
	}

	public void initImportPack(){
		this.fileds.forEach(item->{
			if(item.getJavaType().equals("Date")){
				addImportPacks(item.getJavaFullType());
			}
		});
	}
	
	public void addImportPacks(String importPacks) {		
		
		this.importPacks.add(importPacks);
	}
	
	public List<String> getImportPacks() {
		return importPacks;
	}

	public void setImportPacks(List<String> importPacks) {
		this.importPacks = importPacks;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
		setClassName(StringUtil.firstLetterToUpper(StringUtil.columnToProperty(name)));
	}

	public List<Fileds> getFileds() {
		return fileds;
	}

	public void setFileds(List<Fileds> fileds) {
		this.fileds = fileds;
	}


	@Override
	public String toString() {
		return "Table{" +
				"name='" + name + '\'' +
				", className='" + className + '\'' +
				", importPacks=" + importPacks +
				", fileds=" + fileds +
				", relationTables=" + relationTables +
				", relations=" + relations +
				'}';
	}
}
